<html>
<head><meta charset="utf-8"><title>sink · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html">sink</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183278220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183278220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucio Franco <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183278220">(Dec 12 2019 at 16:51)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> hey! not sure if this is the right place or not, but I was curious in your mind what the status of the <code>futures-sink</code> stuff is and what I might be able to do to take it over the finish line aka not in its own crate but into <code>futures-core</code>. I didn't see any issues around this so just wanted to clear some stuff up. Thanks!</p>



<a name="183285782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183285782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183285782">(Dec 12 2019 at 18:19)</a>:</h4>
<p>I'd like to learn more about what role the sink trait plays</p>



<a name="183286695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183286695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucio Franco <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183286695">(Dec 12 2019 at 18:28)</a>:</h4>
<p>Sure! So a couple of things, high level its used generally in combination with streams to create a chain of async processing. Things like <code>tokio-tower</code> uses both of these interfaces to abstract low level protocols/framing. Currently, lets say we have a stream of items coming in, sink could be used as an interface to forward those items into a buffer for example. Where sink fits in regards to generators and actual language things I am not totally sure. But with futures 0.1 where combinators were heavily used it was really helpful. </p>
<p>For practical use, at least at my work we have used it as a core foundational component <a href="https://github.com/timberio/vector/blob/master/src/sinks/mod.rs#L27" target="_blank" title="https://github.com/timberio/vector/blob/master/src/sinks/mod.rs#L27">https://github.com/timberio/vector/blob/master/src/sinks/mod.rs#L27</a> for how we create logs. So streams are a lower level piece compared to say the tower Service trait.</p>
<p>Happy to explain more if there is something you're more interested in.</p>



<a name="183318493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183318493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183318493">(Dec 13 2019 at 00:47)</a>:</h4>
<p>(deleted)</p>



<a name="183318547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183318547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183318547">(Dec 13 2019 at 00:48)</a>:</h4>
<p>What is the motivation for having the <code>Sink</code> trait in <code>futures-core</code>?</p>



<a name="183318581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183318581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183318581">(Dec 13 2019 at 00:48)</a>:</h4>
<p>Is there something about having it be independently versioned / in a separate crate that is making it difficult to use?</p>



<a name="183318609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183318609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183318609">(Dec 13 2019 at 00:49)</a>:</h4>
<p>I don't know of any open issues that I feel need to be resolved, but I also don't see a reason to take an extra step to tie its version inextricably to that of Stream.</p>



<a name="183330936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183330936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183330936">(Dec 13 2019 at 05:49)</a>:</h4>
<blockquote>
<p>What is the motivation for having the Sink trait in futures-core?</p>
</blockquote>
<p>Why do you think the motivation is different from including <code>Stream</code>? Just because <code>Stream</code> might get special language support? Even though it's not sure whether it's needed? Imho they are just both counterparts of each other. And if the goal of future-rs is to standardize common traits, then it should contain both.</p>



<a name="183331080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183331080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183331080">(Dec 13 2019 at 05:52)</a>:</h4>
<blockquote>
<p>I'd like to learn more about what role the sink trait plays</p>
</blockquote>
<p>As I had written above, to me it is just the <code>write</code> counterpart of the <code>Stream</code>. One reads a value, the other writes a value. E.g. in order to model zero-copy async IO, you would have an object (socket/file/etc) which acts as a <code>Stream&lt;Bytes&gt;</code> for reading from it and a <code>Sink&lt;Bytes&gt;</code> in order to write to it.</p>



<a name="183357519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183357519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183357519">(Dec 13 2019 at 13:13)</a>:</h4>
<p>I agree they are "tied together", but I'm not convinced that we need a <code>Sink</code> abstraction. We have <code>Iterator</code> (a producer) but we have no "consumer" counterpart, for example.</p>



<a name="183357526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183357526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183357526">(Dec 13 2019 at 13:13)</a>:</h4>
<p>I'm not saying it's a problem to have one, but I think at minimum there's no reason they have to go into <em>std</em> together or be versioned together.</p>



<a name="183357537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183357537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183357537">(Dec 13 2019 at 13:13)</a>:</h4>
<p>(I'll try to look at the links <span class="user-mention" data-user-id="207781">@Lucio Franco</span> sent)</p>



<a name="183357602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183357602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183357602">(Dec 13 2019 at 13:14)</a>:</h4>
<p>I guess one could say that the sync consumer is <code>FnMut</code></p>



<a name="183382967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183382967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucio Franco <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183382967">(Dec 13 2019 at 17:57)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> mostly, the question is around confusion for users, if I were new I would expect that sink wasn't ready/I shouldn't use it. So having it in a different crate makes it not as visible as say stream is.</p>



<a name="183383041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183383041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucio Franco <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183383041">(Dec 13 2019 at 17:58)</a>:</h4>
<p>Yeah, maybe it doesn't fit and people need specialized ones but I think we have seen good success with sink in futures 0.1 that it probably doesn't make sense to not include it. Mostly, I just wanted to start a discussion around this.</p>



<a name="183427474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183427474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183427474">(Dec 14 2019 at 06:39)</a>:</h4>
<blockquote>
<p>I agree they are "tied together", but I'm not convinced that we need a Sink abstraction. We have Iterator (a producer) but we have no "consumer" counterpart, for example.</p>
</blockquote>
<p>It might be helpful to decouple the <code>Stream/Sink</code> view  from the <code>Iterator</code> one. Of course a <code>Stream</code> is some kind of iterator, but it is also the primitive interface to read an owned object, which needs a write equivalent. </p>
<p>If we look at byte IO, we have <code>AsyncRead</code> and <code>AsyncWrite</code> for reading and writing values by <strong>copy</strong>. All seem interesting enough for people that they want them to be standardized. For reading data  by <strong>move</strong>, we have <code>Stream</code>. And  <code>Sink</code> would be required for writing data by <strong>move</strong>.</p>
<p>Same goes e.g. for channels. You can abstract the reading side behind a <code>Stream</code>. But there exists no interface for the writing side without <code>Sink</code>.</p>



<a name="183427572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183427572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183427572">(Dec 14 2019 at 06:43)</a>:</h4>
<p><code>FnMut</code> is indeed a suitable interface in the synchronous world. In the async world we however also have to wait until the consumer can accept the data, so the interface needs to be somewhat poll-based. It could theoretically be a single method <code>poll_send(item) -&gt; Poll&lt;Result&lt;(), Err&lt;T&gt;&gt;</code> method. But the current implementation decided to split the process into an synchronous reservation/readiness part and a synchronous submission part.</p>



<a name="183663510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/sink/near/183663510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucio Franco <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/sink.html#183663510">(Dec 17 2019 at 16:15)</a>:</h4>
<p>I would like to note, that the ability to poll_ready has been very useful for us in vector and is the basis for how tower works which is basically a non driven submit trait.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>